﻿@inject Eqwww.App.Identity.UserApp UserApp


@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}

@{ 
    var IsGuanLiYuan = ViewBag.IsGuanLiYuan;
    var IsErJiDanWeiGuanLiYuan = ViewBag.IsErJiDanWeiGuanLiYuan;


}

<link rel="stylesheet" type="text/css" href="~/lib/ztree/css/metroStyle/metroStyle.css" />

<style type="text/css">
    .ztree * {
        font-size:16px;
    }
</style>

<div id="eq-operate1" style="display:none;">
    <div class="mdui-appbar mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar mdui-color-white">
            <a class="eq-operate-cancel-select1" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <div class="mdui-btn-group mdui-hidden-sm-down">
                <a href="javascript:; " onclick="btn_edit()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>edit</i> 修改组织</a>
                <a href="javascript:; " onclick="btn_details()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>remove_red_eye</i> 查看组织</a>
                <a href="javascript:; " onclick="btn_delete()" class="@if (IsErJiDanWeiGuanLiYuan == true) { <text>mdui-hidden</text>} eq-operate-btn mdui-btn mdui-ripple mdui-text-color-pink "><i class='mdui-icon material-icons'>remove_circle_outline</i> 删除组织</a>
                <a href="javascript:; " onclick="btn_createPost()" class="   eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>add</i> 新建科室</a>
            </div>


            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select1 mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>

<div id="eq-operate2" style="display:none;">
    <div class="mdui-appbar mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar mdui-color-white">
            <a class="eq-operate-cancel-select2" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <div class="mdui-btn-group mdui-hidden-sm-down">
                <a href="javascript:; " onclick="btn_editPost()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>edit</i> 修改科室</a>
                <a href="javascript:; " onclick="btn_detailsPost()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>remove_red_eye</i> 查看科室</a>
                <a href="javascript:; " onclick="btn_deletePost()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-pink "><i class='mdui-icon material-icons'>remove_circle_outline</i> 删除科室</a>
                <a href="javascript:; " onclick="btn_createUser()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>add</i> 新建用户</a>
            </div>


            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select2 mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>

<div id="eq-operate3" style="display:none;">
    <div class="mdui-appbar mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar mdui-color-white">
            <a class="eq-operate-cancel-select3" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <div class="mdui-btn-group mdui-hidden-sm-down">
            <a href="javascript:; " onclick="btn_editUser()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>edit</i> 修改用户</a>
            <a href="javascript:; " onclick="btn_detailsUser()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>remove_red_eye</i> 查看用户</a>
            <a href="javascript:; " onclick="btn_deleteUser()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-pink "><i class='mdui-icon material-icons'>remove_circle_outline</i> 删除用户</a>
            <a href="javascript:; " onclick="btn_rolerelation()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>group_add</i> 角色关联</a>
            <a href="javascript:; " onclick="btn_postrelation()" class="eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>group_work</i> 岗位调动</a>
            </div>


            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select3 mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>

<div class="mdui-appbar mdui-shadow-1">
    <div class="mdui-toolbar mdui-color-white">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <div class="mdui-toolbar-spacer"></div>


        <div class="mdui-btn-group">
        <a href="javascript:; " onclick="btn_create()" class=" @if (IsErJiDanWeiGuanLiYuan == true) { <text>mdui-hidden</text>}  eq-operate-btn mdui-btn mdui-ripple mdui-text-color-theme "><i class='mdui-icon material-icons'>add</i> 新建组织</a>

        </div>



    </div>
</div>

<div class="mdui-container mdui-m-t-3 mdui-m-b-3">

    <div>
        <ul id="treeDemo" class="ztree"></ul>
    </div>

</div>

@section Scripts {

    <script src="~/lib/ztree/js/jquery.ztree.all.js"></script>

    <script>

        var zTreeObj;

        var checkedNode = null;

        // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
        var setting = {
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid",
                    rootPId:null
                }
            },

            callback: {
                onClick: onClick
            }
        };
        // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
        var zNodes = @Html.Raw(ViewData["ztree"]);

        $(function () {
                $('.eq-list-table').eqTable();

                $('#refreshBtn').bind('click', function () {
                    top.$.loading(false);
                    window.location.reload();
            });

            initZtree();

            $('.eq-operate-cancel-select1').click(function () {
                $('#eq-operate1').hide();
                $('#eq-operate2').hide();
                $('#eq-operate3').hide();
                checkedNode = null;
            })
            $('.eq-operate-cancel-select2').click(function () {
                $('#eq-operate1').hide();
                $('#eq-operate2').hide();
                $('#eq-operate3').hide();
                checkedNode = null;
            })
            $('.eq-operate-cancel-select3').click(function () {
                $('#eq-operate1').hide();
                $('#eq-operate2').hide();
                $('#eq-operate3').hide();
                checkedNode = null;
            })
        });

        function initZtree() {
            zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);

        }

        function onClick(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            var nodeType = treeNode.nodetype;
            if (nodeType == "organize") {
                $('#eq-operate1').show();
                $('#eq-operate2').hide();
                $('#eq-operate3').hide();
            }
            else if (nodeType == "post") {
                $('#eq-operate2').show();
                $('#eq-operate1').hide();
                $('#eq-operate3').hide();
            }
            else if (nodeType == "user") {
                $('#eq-operate3').show();
                $('#eq-operate1').hide();
                $('#eq-operate2').hide();
            }

            checkedNode = treeNode;
        }


        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建组织',
                url: '/SystemManage/Organize/Create',
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_createPost() {
            var key = checkedNode.id;
            var name = checkedNode.name;
            if (checkedNode.nodetype != 'organize') {
                $.modalMessage('选中行不是【组织】类型！');
                return false;
            }
            $.modalOpen({
                id: 'formCreate',
                title: '新建科室',
                url: '/SystemManage/Post/Create?organizeId='+key+'&organizeName='+name,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_createUser() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'post') {
                $.modalMessage('选中行不是【科室】类型！');
                return false;
            }

            $.modalOpen({
                id: 'formCreate',
                title: '新建用户',
                url: '/SystemManage/User/Create?postid='+key,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }


        function btn_edit() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'organize') {
                $.modalMessage('选中行不是【组织】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '修改组织',
                url: '/SystemManage/Organize/Edit?id=' + key,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_details() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'organize') {
                $.modalMessage('选中行不是【组织】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看组织',
                url: '/SystemManage/Organize/Details?id=' + key,
                width: '500px',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_delete() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'organize') {
                $.modalMessage('选中行不是【组织】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            $.deleteForm({
                url: '/SystemManage/Organize/Delete',
                param: { id: key },
                success: function (iframeId) {
                    window.location.reload();

                }
            })
        }


        function btn_editPost() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'post') {
                $.modalMessage('选中行不是【科室】类型！');
                return false;
            }

            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '修改',
                url: '/SystemManage/Post/Edit?id=' + key,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_detailsPost() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'post') {
                $.modalMessage('选中行不是【科室】类型！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/Post/Details?id=' + key,
                width: '500px',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_deletePost() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'post') {
                $.modalMessage('选中行不是【科室】类型！');
                return false;
            }

            $.deleteForm({
                url: '/SystemManage/Post/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }


        function btn_editUser() {
            var key = checkedNode.id;
            //alert(JSON.stringify(checkedNode));
            if (checkedNode.nodetype != 'user') {
                $.modalMessage('选中行不是【用户】类型！');
                return false;
            }

            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }


            $.modalOpen({
                id: 'formEditButton',
                title: '修改',
                url: '/SystemManage/User/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_detailsUser() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'user') {
                $.modalMessage('选中行不是【用户】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/User/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_deleteUser() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'user') {
                $.modalMessage('选中行不是【用户】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }


            $.deleteForm({
                url: '/SystemManage/User/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }

        function btn_postrelation() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'user') {
                $.modalMessage('选中行不是【用户】类型！');
                return false;
            }
           
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            

            $.modalOpen({
                id: 'formEditButton',
                title: '岗位调动',
                url: '/SystemManage/User/PostRelation?id=' + key,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_rolerelation() {
            var key = checkedNode.id;
            if (checkedNode.nodetype != 'user') {
                $.modalMessage('选中行不是【用户】类型！');
                return false;
            }
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '角色关联',
                url: '/SystemManage/User/RoleRelation?id=' + key,
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }



    </script>
}
